#include <QFocusEvent>
#include "MyLineEdit.h"

MyLineEdit::MyLineEdit(QWidget *parent)
    : QLineEdit(parent)
{
    setText("0.0");
    connect(this, SIGNAL(textChanged(QString)), this,SLOT(onValueChanged(QString)));
}

void MyLineEdit::focusInEvent(QFocusEvent *)
{
    setSelection(0, text().length());
}

void MyLineEdit::mousePressEvent(QMouseEvent *)
{
    setSelection(0, text().length());
}

void MyLineEdit::onValueChanged(QString arg)
{
    if (arg.isEmpty()) {
        setText("0.0");
    }
    else {
        emit valueChanged(arg, this);
    }
}
